package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goods.catbrand.CatAndBrand;
import com.cskaoyan.bean.goods.Goods4Class;
import com.cskaoyan.bean.goods.MarketGoods;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Hu
 * @create 2021-09-16 19:34
 * @Description
 */


@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, Integer goodsId, String goodsSn, String name) {
        BaseData<MarketGoods> result = goodsService.list(baseParam, goodsId, goodsSn, name);
        return BaseRespVo.ok(result);
    }



    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Goods4Class goodsInfo) {
        goodsService.create(goodsInfo);

        return BaseRespVo.ok();
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        Goods4Class detail = goodsService.detail(id);
        return BaseRespVo.ok(detail);
    }

//逻辑删除 update 表delete colum为0
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketGoods goods) {
        Integer id = goods.getId();
        goodsService.delete(id);
        return BaseRespVo.ok();
    }


    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Goods4Class goodsInfo) {
        goodsService.update(goodsInfo);
        return BaseRespVo.ok();
    }


    //编辑页面 空参 给L1L2表
    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        CatAndBrand catAndBrand = goodsService.catAndBrand();
        return BaseRespVo.ok(catAndBrand);
    }


}
